package com.example.springboot_vue.controller;

import com.example.springboot_vue.entity.Student;
import com.example.springboot_vue.service.StudentService;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
@RestController
@RequestMapping(value="/student")
@CrossOrigin // 允许跨域，但是不能携带其他的请求头
public class StudentController {

    @Resource
    private StudentService studentService;

    @GetMapping(value="/{id}")
    public Student findById(@PathVariable("id") Integer id){

        return studentService.findById(id);

    };

    @GetMapping()
    public List<Student> findAll(){
        return studentService.findAll();
    };

    @PostMapping(value="/update")
    public Map<String, Object> update(Student student){
        return studentService.update(student);
    };

    @PostMapping(value="/add")
    public Map<String, Object> add(Student student){
        return studentService.add(student);
    };

    @GetMapping(value = "/delete/{id}")
    public Map<String, Object> deleteById(@PathVariable("id") Integer id ){
        return studentService.deleteById(id);
    };
}


